<?php
declare (strict_types=1);

namespace app\common\model;

use think\model\relation\BelongsTo;
/**
 * @mixin \think\Model
 */
class ProductSearchLog extends Base
{
    protected $name = 'product_search_log';

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'uid', 'id')->field('id,nickname,code,mobile,province,city,district');
    }

    public function getAreaAttr($value, $data): string
    {
        if($district = User::where('id', $data['uid'])->value('district')){
            return Area::where('code', $district)->value('concat_ws("/", province,city,district) as area');
        }
        return '';
    }
}
